from tkinter import *
root = Tk()
def callback1():
    print("打开")
    print(openVar.get())

def callback2():
    print("关闭")
    print(closeVar.get())

def callback3():
    print("退出")
    print(exitVar.get())

def callback4():
    print("剪贴")
    print(editVar.get())

def callback5():
    print("拷贝")
    print(editVar.get())

def callback6():
    print("粘贴")
    print(editVar.get())

#创建checkbutton关联变量
openVar = IntVar()
closeVar = IntVar()
exitVar = IntVar()

menubar = Menu(root)  #创建一个顶级菜单
filemenu = Menu(menubar,tearoff = False) #创建一个顶级菜单下的子菜单
menubar.add_cascade(label = "文件",menu = filemenu)  #为子菜单起个名字
filemenu.add_checkbutton(label = "打开",command = callback1,variable = openVar)
filemenu.add_checkbutton(label = "关闭",command = callback2,variable = closeVar)
filemenu.add_separator()  #增加分隔符
filemenu.add_checkbutton(label = "退出",command = callback3,variable = exitVar)

#创建radiobutton关联变量
editVar = IntVar()
editVar.set(1)
editmenu = Menu(menubar,tearoff = False)
menubar.add_cascade(label = "编辑",menu = editmenu)
editmenu.add_radiobutton(label = "剪贴",command = callback4,variable = editVar,value = 1)
editmenu.add_radiobutton(label = "拷贝",command = callback5,variable = editVar,value = 2)
editmenu.add_radiobutton(label = "粘贴",command = callback6,variable = editVar,value = 3)

#显示菜单
root.config(menu = menubar)
mainloop()
